package com.lmonkey.servlet.user;

import com.lmonkey.com.lmonkey.service.LMONKEY_USERDao;
import com.lmonkey.entity.LMONKEY_CAIDAN;
import com.lmonkey.entity.LMONKEY_USER;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/manager/admin_DoUserSelect")
public class DoSelect extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        int cpage=1;
        int count=5;


        String cp=request.getParameter("cp");


        String keyword=request.getParameter("keyword");

        if (cp!=null){
            cpage=Integer.parseInt(cp);
        }


        int arr[]= new int[100];
        try {
            arr = LMONKEY_USERDao.totalPage(count,keyword);
        } catch (SQLException e) {
            e.printStackTrace();
        }



        ArrayList<LMONKEY_USER> list= null;
        try {
            list = LMONKEY_USERDao.selectAll(cpage,count,keyword);
        } catch (SQLException e) {
            e.printStackTrace();
        }


        request.setAttribute("userlist",list);
        request.setAttribute("tsum",arr[0]);
        request.setAttribute("tpage",arr[1]);
        request.setAttribute("cpage",cpage);


        if (keyword!=null){
            request.setAttribute("searchParams","&keyword="+keyword);

        }




        request.getRequestDispatcher("/manager/admin_user.jsp").forward(request,response);
    }
}
